<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram</title>
<style>
    body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
        background-color: #f0f0f0;
    }
    canvas {
        background-color: #ffffff;
        border: 1px solid #ccc;
    }
</style>
</head>
<body>
<canvas id="physicsCanvas" width="500" height="400"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Style settings to mimic the hand-drawn look
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.lineWidth = 2.5;
    ctx.lineCap = 'round';

    // Helper function to draw a line with an arrowhead
    function drawArrow(x1, y1, x2, y2) {
        const headlen = 12; // length of head in pixels
        const angle = Math.atan2(y2 - y1, x2 - x1);

        // Main line
        ctx.beginPath();
        ctx.moveTo(x1, y1);
        ctx.lineTo(x2, y2);
        ctx.stroke();

        // Arrowhead
        ctx.beginPath();
        ctx.moveTo(x2, y2);
        ctx.lineTo(x2 - headlen * Math.cos(angle - Math.PI / 7), y2 - headlen * Math.sin(angle - Math.PI / 7));
        ctx.lineTo(x2 - headlen * Math.cos(angle + Math.PI / 7), y2 - headlen * Math.sin(angle + Math.PI / 7));
        ctx.closePath();
        ctx.fill();
    }
    
    // --- Main Drawing ---

    const origin = { x: 250, y: 220 };
    const axisLength = 120;
    const vectorLength = 90;

    // Set font for labels
    ctx.font = "italic bold 22px 'Times New Roman'";

    // Draw Z-axis (up)
    drawArrow(origin.x, origin.y, origin.x, origin.y - axisLength);
    ctx.fillText('z', origin.x - 5, origin.y - axisLength - 10);

    // Draw Y-axis (right)
    drawArrow(origin.x, origin.y, origin.x + axisLength, origin.y);
    ctx.fillText('y', origin.x + axisLength + 10, origin.y + 8);

    // Draw X-axis (down-left)
    // In canvas coordinates (y-down), this angle is in the second quadrant.
    const xAxisAngle = 140 * Math.PI / 180;
    const xEnd = {
        x: origin.x + axisLength * Math.cos(xAxisAngle),
        y: origin.y + axisLength * Math.sin(xAxisAngle)
    };
    drawArrow(origin.x, origin.y, xEnd.x, xEnd.y);
    ctx.fillText('x', xEnd.x - 20, xEnd.y + 10);

    // Label Origin
    ctx.font = "bold 22px 'Times New Roman'";
    ctx.fillText('O', origin.x + 8, origin.y - 5);


    // Draw Vector P1 (along x-axis)
    const p1End = {
        x: origin.x + vectorLength * Math.cos(xAxisAngle),
        y: origin.y + vectorLength * Math.sin(xAxisAngle)
    };
    drawArrow(origin.x, origin.y, p1End.x, p1End.y);
    
    // Label P1
    ctx.font = "bold 24px 'Times New Roman'";
    ctx.fillText('P', p1End.x - 38, p1End.y - 15);
    ctx.font = "bold 16px 'Times New Roman'";
    ctx.fillText('1', p1End.x - 24, p1End.y - 10);


    // Draw Vector P2 (in xy-plane, visually down-right)
    const p2Angle = 35 * Math.PI / 180;
    const p2End = {
        x: origin.x + vectorLength * Math.cos(p2Angle),
        y: origin.y + vectorLength * Math.sin(p2Angle)
    };
    drawArrow(origin.x, origin.y, p2End.x, p2End.y);

    // Label P2
    ctx.font = "bold 24px 'Times New Roman'";
    ctx.fillText('P', p2End.x - 5, p2End.y + 28);
    ctx.font = "bold 16px 'Times New Roman'";
    ctx.fillText('2', p2End.x + 9, p2End.y + 33);


    // Draw Angle Arc and Label for φ₀
    ctx.lineWidth = 1.5;
    const arcRadius = 40;
    ctx.beginPath();
    // The arc is drawn from P2 to P1 visually, which is counter-clockwise on the canvas
    ctx.arc(origin.x, origin.y, arcRadius, p2Angle, xAxisAngle, false);
    ctx.stroke();

    // Label φ₀
    const midAngle = (p2Angle + xAxisAngle) / 2;
    const labelRadius = arcRadius - 15;
    const phiPos = {
        x: origin.x + labelRadius * Math.cos(midAngle),
        y: origin.y + labelRadius * Math.sin(midAngle)
    };
    ctx.font = "italic 22px 'Times New Roman'";
    ctx.fillText('φ', phiPos.x - 3, phiPos.y + 8);
    ctx.font = "italic 16px 'Times New Roman'";
    ctx.fillText('0', phiPos.x + 8, phiPos.y + 13);
    
    
    // Draw Caption
    ctx.font = "bold 20px 'Times New Roman'";
    ctx.fillStyle = 'black';
    ctx.textAlign = 'center';
    ctx.fillText('Fig. 4.36', canvas.width / 2, canvas.height - 20);

</script>
</body>
</html>